//driver.cpp
/********************************************************************************
*																				*
*	Author:			Jared Szechy												*
*	Assignment:		Assignment 7												*
*	Class:			CPS-151														*
*	Instructor:		V. Starkley													*
*	Due Date:		October 26													*
*																				*
*	This program demonstrates the use of linked stacks.							*
*																				*
********************************************************************************/

#include <iostream>
#include <string>
using namespace std;
#include "stack.h"


template<class ItemType>
void PrintStack(ostream& dataFile, StackType<ItemType> s, string stackName);
//pre:  dataFile is open for output
//pre:  all items from s are displayed to dataFile

int main()
{
	StackType<int> stack1, stack2, stack3, stack4, stack5, stack6, stack7;

	//Test identical function
	cout << "Testing the indentical function" << endl << endl;
	
		//Both empty
		cout << "Testing 2 empty stacks" << endl;
		if (stack1.Identical(stack2))
			cout << "The stacks are identical" << endl << endl;
		else
			cout << "The stacks are not identical" << endl << endl;

		//One empty, one loaded
		cout << "Testing One empty, one loaded stacks" << endl;
		stack1.Push(3);
		stack1.Push(2);
		stack1.Push(5);
		if (stack1.Identical(stack2))
			cout << "The stacks are identical" << endl << endl;
		else
			cout << "The stacks are not identical" << endl;

		//Two identical loaded stacks
		cout << "Testing 2 identical loaded stacks" << endl << endl;
		stack2.Push(3);
		stack2.Push(2);
		stack2.Push(5);
		if (stack1.Identical(stack2))
			cout << "The stacks are identical" << endl << endl;
		else
			cout << "The stacks are not identical" << endl << endl;

		//Two differnt loaded stacks
		cout << "Testing 2 different loaded stacks" << endl;
		stack3.Push(2);
		stack3.Push(4);
		stack3.Push(1);
		if (stack1.Identical(stack3))
			cout << "The stacks are identical" << endl << endl;
		else
			cout << "The stacks are not identical" << endl << endl;
	
	//Test append function
	cout << "Testing append function" << endl << endl;

		//2 loaded stacks
		cout << "testing 2 loaded stacks" << endl;
		PrintStack(cout, stack1, "1");
		PrintStack(cout, stack2, "2");
		stack3 = stack1.appendStack(stack2);
		PrintStack(cout, stack3, "3");
		cout << endl;

		//2 empty stacks
		cout << "testing 2 empty stacks" << endl;
		PrintStack(cout, stack4, "1");
		PrintStack(cout, stack5, "2");
		stack3 = stack4.appendStack(stack5);
		PrintStack(cout, stack3, "3");
		cout << endl;

		//first empty second loaded
		cout << "testing first empty second loaded" << endl;
		PrintStack(cout, stack4, "1");
		PrintStack(cout, stack1, "2");
		stack3 = stack4.appendStack(stack1);
		PrintStack(cout, stack3, "3");
		cout << endl;

		//first loaded second empty
		cout << "testing first loaded second empty" << endl;
		PrintStack(cout, stack3, "1");
		PrintStack(cout, stack4, "2");
		stack5 = stack3.appendStack(stack4);
		PrintStack(cout, stack5, "3");
		cout << endl;

	//Test split function
	cout << "Testing split function" << endl << endl;
		
		//2 an empty stack
		cout << "testing 2 empty stacks" << endl;
		stack7.splitStack(stack5, stack6, 4);
		PrintStack(cout, stack5, "low");
		PrintStack(cout, stack6, "high");
		cout << endl;

		//all less than
		stack7.Push(2);
		stack7.Push(1);
		stack7.Push(3);
		cout << "testing all less than value" << endl;
		stack7.splitStack(stack5, stack6, 4);
		PrintStack(cout, stack5, "low");
		PrintStack(cout, stack6, "high");
		cout << endl;

		//all greater than
		stack6.Push(7);
		stack6.Push(6);
		stack6.Push(5);
		cout << "testing all greater than value" << endl;
		stack6.splitStack(stack5, stack7, 4);
		PrintStack(cout, stack5, "low");
		PrintStack(cout, stack7, "high");
		cout << endl;

		//higher and lower
		stack6.Push(2);
		stack6.Push(1);
		stack6.Push(3);
		cout << "testing higher and lower than value" << endl;
		stack6.splitStack(stack5, stack7, 4);
		PrintStack(cout, stack5, "low");
		PrintStack(cout, stack7, "high");
		cout << endl;

	system("pause");
}//end main





template<class ItemType>
void PrintStack(ostream& dataFile, StackType<ItemType> s, string stackName)
{
	ItemType item;

	if (s.IsEmpty())
	{
		dataFile << "Stack " << stackName << " is empty.\n";
		return;
	}
	
	dataFile << "Stack " << stackName << " contains the following items:\n";
	while(s.Pop(item))
	{
		dataFile << item << endl;
	}
	dataFile << endl;
}
